

public class LogIn {
    private String userName = "admin";
    private String password = "123456";


    public  void loginInfo(String userName, String password) throws UserNameException{
        if(!this.userName.equals(userName)) {
            throw new UserNameException(userName + "用户名错误！");
            /*System.out.println("用户名错误！");*/

        }
        if(!this.password.equals(password)) {
            throw new PassWordException(password + "密码错误！");
            /*System.out.println("密码错误！");*/

        }
        System.out.println("登录成功");

    }

    public static void main(String[] args) {
        LogIn logIn = new LogIn();
        try {
            logIn.loginInfo("admn","123456");
            //我们继承的是Exception那么就默认是受查异常，所以就需要进行处理才能通过编译

        } catch (UserNameException e) {
            e.printStackTrace();
        } catch (PassWordException e) {
            e.printStackTrace();
        }

    }
}
